package test.meituan;

import java.util.Scanner;

/**
 * @description:
 * @author: w_jingbo
 * @date: 2023/9/9
 * @Copyright: 博客：http://coisini.wang
 */
public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine());
        String[] s = in.nextLine().split(" ");
        int[] arr = new int[n] ;

        boolean flag = false ;
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(s[i]);
        }
        int sum = arr[0] ;
        int k = 0 ;
        int max = 0 ;
        for (int i = 1; i < n; i++) {
            if(sum < arr[i]){
                sum += arr[i] ;
                continue;
            }
            if(arr[i] > max){
                sum += arr[i] ;
                max = arr[i] ;
                k  = i ;
            }

        }
        sum = 0 ;
        if(k == 0){
            System.out.println(-1);
            return;
        }
        for (int i = 0; i < n; i++) {
            if(i == k){
                sum -= arr[i] ;
            }else {
                sum += arr[i] ;
            }
        }
        System.out.println(sum);


    }
}


/*
7
1 3 7 8 6 5 2
String str1 = in.nextLine() ;
        int k = Integer.parseInt(in.nextLine());

        for (int i = 0; i < k; i++) {
            String str2 = "" ;
            for(int j = 0 ; j < str1.length() ; j++){
                if(str1.charAt(j) == 'a'){
                    str2 += "bc" ;
                }else if(str1.charAt(j) == 'b'){
                    str2 += "ca" ;
                }else {
                    str2 += "ab" ;
                }
            }
            str1 = str2 ;
        }
        System.out.println(str1);


 */
